package com.itfenghuang.day18_lx;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
/*
3. 写一个登陆的表单,点击登陆之后请求一个Servlet(LoginServlet)
     *      在这个Servlet中:获取用户名和密码,然后将用户名和密码存到会话域
     *      然后在浏览器发送一个请求,发到另外一个Servlet上(IndexServlet)
     *      在IndexServlet中:从会话域中获取到刚才存储的用户名和密码,然后响应
     *      给浏览器一句话:"欢迎你: xxx"
     *      分析: 1).创建LoginServlet类   getParameter()
     *           2).保存到会话域中, 获取HttpSession对象,  之后使用setAttribute() 添加
     *           3).创建IndexServlet类
     *           4).获取HttpSession对象,然后通过getAttribute()取出来,
     *           5).响应到浏览器
 */

public class A02_zuoye extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String pt = req.getParameter("username");
        String pd = req.getParameter("password");
        HttpSession ss = req.getSession();
        ss.setAttribute("username",pt);
        ss.setAttribute("password",pd);
        resp.sendRedirect("/a2zuoye1");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       doGet(req, resp);
    }
    public void show(){}
}
